define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    var Controller = {
        index: function () {
            var community_id = GetQueryString('community_id');
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'communitymember/index?community_id='+community_id,
                    add_url: '',
                    edit_url: '',
                    del_url: 's',
                    multi_url: 'communitymember/multi',
                    table: 'community_member',
                }
            },
            );

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                //commonSearch: false,
                showToggle: false,
                showColumns: false,
                columns: [
                    [
                       /* {checkbox: true},*/
                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'community.name', title: __('Community_id'), operate: 'LIKE %...%'},
                        {field: 'user_name', title: __('User_id'), operate: 'LIKE %...%', operate:false},
                        {field: 'createtime', title: __('Createtime'),operate:false, formatter: Table.api.formatter.datetime, operate:false},
                        {field: 'expiretime', title: __('Expiretime'),operate:false, formatter: Table.api.formatter.datetime},
                        {field: 'paid_text', title: __('Paid'), operate:false, formatter: Controller.api.formatter.paid},
                        {field: 'paid', title: __('Paid'),visible: false, searchList: {'0': '未支付', '1': '已支付'},},
                        {field: 'state', title: __('State'), align: 'center', formatter: Controller.api.formatter.state, searchList: {'0': '未认证', '1': '已认证'},},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            formatter: {
                state: function (value, row, index) {
                    return "<a href='javascript:;' class='btn btn-" + (value ? "info" : "danger") + " btn-xs btn-change' data-id='"
                            + row.id + "' data-params='state=" + (value ? 0 : 1) + "'>" + (value ? '已认证' : '未认证') + "</a>";
                },
                paid: function (value, row, index) {
                    if(value == '未支付'){
                        return "<font style='color:red'>"+value+"</font>";
                    }
                    else
                    {
                        return value;
                    }
                },
            },
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
        }
    };
    return Controller;
});